package pl.edu.pw.tm.zestawfiltrow.algorytmy;

import java.awt.image.BufferedImage;

public class Average extends LinearFilter {
	private static String name = "Uśredniający";
	private int[][] mask = {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}};
	
	
	@Override
	public BufferedImage run(BufferedImage img) {
		
		int rgb;
		int width = img.getWidth();
		int height = img.getHeight();
		BufferedImage newImage = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
		int[][] px = getPixels(img);
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				if(i <1 || j<1 || i >= width-1 || j >= height-1){
					rgb = toRGB(0, 0, 0);
					newImage.setRGB(i, j, (int) rgb);
				}
				else {
					newImage.setRGB(i, j, getMaskedValue(i, j, px));
				}				
			}
		}
		return newImage;
	}

	public String getName() {
		return name;
	}

	@Override
	protected int[][] getMask() {		
		return mask;
	}
}